home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Floppyshop 2
/
Floppyshop - 2.zip
/
Floppyshop - 2.iso
/
art&graf.ix
/
art-0039
/
source
/
dcconvrt.mod
< prev
next >
Wrap
Text File
|
1997-04-16
|
17KB
|
516 lines
IMPLEMENTATION MODULE DCConvrt;
(*----------------------------------------------------------------------*)
(* This module will need to access the screen display routines. *)
(*----------------------------------------------------------------------*)
(*--------------------------------------------------------------------*)
(* Amendments: *)
(* 25/ 8/89 LGM : Changed to use new Picture conversion routines. *)
(* Make print patterns for equal colours the same. *)
(* *)
(*--------------------------------------------------------------------*)
(* IMPORT Trace; *)
FROM SYSTEM IMPORT ADR, ADDRESS;
FROM Strings IMPORT String, Concat, Assign;
FROM QSort IMPORT SortArrayWithKeys;
IMPORT Forms;
IMPORT DCPicCnv; (* low-level picture conversion routines *)
FROM DCScreen IMPORT DisplayPicture;
FROM DCQScrn IMPORT ClearScreen;
FROM DCGlobal IMPORT (* Constants *)
LowRes,
MedRes,
HiRes,
LowResMaxX,
LowResMaxY,
MedResMaxX,
MedResMaxY,
HiResMaxX,
HiResMaxY,
LowResScreen,
MedResScreen,
HiResScreen,
BitPlanesEnum,
HiResLinePixelGroups,
MedResLinePixelGroups,
LowResLinePixelGroups,
DegasPicture,
PrintPalette,
Palette,
PaletteEntry,
PrintBitPatternSet;
FROM ManyWindows IMPORT ShowAlert;
FROM Graphics IMPORT graf_mouse;
TYPE
PaletteEntryPtr = POINTER TO PaletteEntry;
CONST
CLinesToDisplay = 20;
Arrow = 0;
HourGlass = 2;
PROCEDURE NullFill( VAR s : ARRAY OF CHAR );
VAR i : INTEGER;
BEGIN
FOR i := 0 TO SHORT(HIGH(s)) DO s[i] := 0C; END;
END NullFill;
PROCEDURE ConvertDegasToHiRes ( VAR inpicture,
outpicture : DegasPicture;
VAR printpalette : PrintPalette );
VAR Dumc : CARDINAL;
BEGIN
Dumc := graf_mouse( HourGlass, NIL);
IF inpicture.resolution = MedRes THEN
ConvertMedDegasToHiRes ( inpicture, outpicture, printpalette );
ELSIF inpicture.resolution = LowRes THEN
ConvertLowDegasToHiRes ( inpicture, outpicture, printpalette );
ELSE
outpicture := inpicture;
END; (* if *)
Dumc := graf_mouse( Arrow, NIL);
END ConvertDegasToHiRes;
(*----------------------------------------------------------------------*)
(* PrintPalette will already have been set up *)
(*----------------------------------------------------------------------*)
PROCEDURE ConvertMedDegasToHiRes ( VAR inpicture,
outpicture : DegasPicture;
VAR printpalette : PrintPalette );
VAR i : INTEGER;
BEGIN
ClearPicture( outpicture );
FOR i := 0 TO MedResMaxY DO
DCPicCnv.ConvertMedToHiResOneLine( inpicture, outpicture,
printpalette, i);
IF ( i MOD CLinesToDisplay ) = 0 THEN
DisplayPicture ( outpicture.HiResPicture );
END; (* if *)
END; (* for i *)
DisplayPicture ( outpicture.HiResPicture );
END ConvertMedDegasToHiRes;
PROCEDURE ConvertLowDegasToHiRes ( VAR inpicture,
outpicture : DegasPicture;
VAR printpalette : PrintPalette );
VAR i : INTEGER;
BEGIN
ClearPicture( outpicture );
FOR i := 0 TO LowResMaxY DO
DCPicCnv.ConvertLowToHiResOneLine( inpicture, outpicture,
printpalette, i);
IF ( i MOD CLinesToDisplay ) = 0 THEN
DisplayPicture ( outpicture.HiResPicture );
END; (* if *)
END; (* for i *)
DisplayPicture ( outpicture.HiResPicture );
END ConvertLowDegasToHiRes;
PROCEDURE ClearPicture ( VAR picture : DegasPicture );
VAR i,j : INTEGER;
BEGIN
picture.resolution := HiRes;
picture.HiPalette[0] := 1;
picture.HiPalette[1] := 0;
ClearScreen(picture.HiResPicture);
END ClearPicture;
PROCEDURE ShowLowResPixelIndex( x, y : INTEGER;
screenres : INTEGER;
VAR inpicture : DegasPicture;
VAR pp : PrintPalette );
CONST
Crgb = 'RGB = ';
Cindex = 'Index = ';
Cpp = 'Pattern = ';
Cspace = ' ';
VAR
s, temps : String;
i, j : INTEGER;
BEGIN
IF screenres = HiRes THEN
x := x DIV 2; y := y DIV 2;
ELSE
x := x DIV 2;
END;
i := DCPicCnv.QueryXYLowResPixelIndex( x, y, inpicture);
NullFill(s);
Assign(Crgb,s);
NullFill(temps);
temps[0] := CHR( CARDINAL(pp[i].RedComponent) + ORD('0') );
temps[1] := CHR( CARDINAL(pp[i].GreenComponent) + ORD('0') );
temps[2] := CHR( CARDINAL(pp[i].BlueComponent) + ORD('0') );
Concat(s,temps,s);
Concat(s,Cspace,s);
Concat(s,Cindex,s);
NullFill(temps);
j := pp[i].ColourIndex;
IF j > 9 THEN
temps[0] := '1';
j := j - 10;
ELSE
temps[0] := '0';
END;
temps[1] := CHR( CARDINAL(j) + ORD('0') );
Concat(s,temps,s);
Concat(s,Cspace,s);
Concat(s,Cpp,s);
Assign('0000',temps);
IF 0 IN pp[i].PrintBitPattern THEN temps[3] := '1' END;
IF 1 IN pp[i].PrintBitPattern THEN temps[2] := '1' END;
IF 2 IN pp[i].PrintBitPattern THEN temps[1] := '1' END;
IF 3 IN pp[i].PrintBitPattern THEN temps[0] := '1' END;
Concat(s,temps,s);
j := ShowAlert(s,1,1);
END ShowLowResPixelIndex;
PROCEDURE ShowMedResPixelIndex( x, y : INTEGER;
screenres : INTEGER;
VAR inpicture : DegasPicture;
VAR pp : PrintPalette );
CONST
Crgb = 'RGB = ';
Cindex = 'Index = ';
Cpp = 'Pattern = ';
Cspace = ' ';
VAR
s, temps : String;
i, j : INTEGER;
BEGIN
IF screenres = HiRes THEN
y := y DIV 2;
END;
i := DCPicCnv.QueryXYMedResPixelIndex( x, y, inpicture);
NullFill(s);
Assign(Crgb,s);
NullFill(temps);
temps[0] := CHR( CARDINAL(pp[i].RedComponent) + ORD('0') );
temps[1] := CHR( CARDINAL(pp[i].GreenComponent) + ORD('0') );
temps[2] := CHR( CARDINAL(pp[i].BlueComponent) + ORD('0') );
Concat(s,temps,s);
Concat(s,Cspace,s);
Concat(s,Cindex,s);
NullFill(temps);
j := pp[i].ColourIndex;
IF j > 9 THEN
temps[0] := '1';
j := j - 10;
ELSE
temps[0] := '0';
END;
temps[1] := CHR( CARDINAL(j) + ORD('0') );
Concat(s,temps,s);
Concat(s,Cspace,s);
Concat(s,Cpp,s);
Assign('0000',temps);
IF 0 IN pp[i].PrintBitPattern THEN temps[3] := '1' END;
IF 1 IN pp[i].PrintBitPattern THEN temps[2] := '1' END;
IF 2 IN pp[i].PrintBitPattern THEN temps[1] := '1' END;
IF 3 IN pp[i].PrintBitPattern THEN temps[0] := '1' END;
Concat(s,temps,s);
j := ShowAlert(s,1,1);
END ShowMedResPixelIndex;
(*----------------------------------------------------------------------*)
(* Split colour value into its red, green and blue components. *)
(*----------------------------------------------------------------------*)
PROCEDURE ColourComponents ( colour : INTEGER;
VAR red, green, blue : INTEGER );
CONST
CLeftShift4 = 16;
CColourComponentMask = {13,14,15};
BEGIN
blue := INTEGER ( BITSET(colour) * CColourComponentMask );
colour := colour DIV CLeftShift4;
green := INTEGER ( BITSET(colour) * CColourComponentMask );
colour := colour DIV CLeftShift4;
red := INTEGER ( BITSET(colour) * CColourComponentMask );
END ColourComponents;
PROCEDURE CountPBPBits( bits : PrintBitPatternSet ) : CARDINAL;
VAR cnt : CARDINAL;
BEGIN
cnt := 0;
IF 0 IN bits THEN INC(cnt); END;
IF 1 IN bits THEN INC(cnt); END;
IF 2 IN bits THEN INC(cnt); END;
IF 3 IN bits THEN INC(cnt); END;
RETURN cnt;
END CountPBPBits;
PROCEDURE CompareComponents( PE1Ptr, PE2Ptr : PaletteEntryPtr ) : BOOLEAN;
VAR colour1, colour2 : CARDINAL;
result : BOOLEAN;
BEGIN
result := FALSE;
WITH PE1Ptr^ DO
colour1 := ( ( RedComponent * 100 )
+ ( GreenComponent * 10 )
+ ( BlueComponent * 1 ) )
END; (* with *)
WITH PE2Ptr^ DO
colour2 := ( ( RedComponent * 100 )
+ ( GreenComponent * 10 )
+ ( BlueComponent * 1 ) )
END; (* with *)
result := ( colour1 < colour2 ) ;
IF colour1 = colour2 THEN
IF CountPBPBits(PE1Ptr^.PrintBitPattern)
> CountPBPBits(PE2Ptr^.PrintBitPattern) THEN
result := TRUE;
END;
END;
RETURN result;
END CompareComponents;
PROCEDURE CompareCompEqual( PE1, PE2 : PaletteEntry ) : BOOLEAN;
VAR colour1, colour2 : CARDINAL;
BEGIN
WITH PE1 DO
colour1 := ( ( RedComponent * 100 )
+ ( GreenComponent * 10 )
+ ( BlueComponent * 1 ) )
END; (* with *)
WITH PE2 DO
colour2 := ( ( RedComponent * 100 )
+ ( GreenComponent * 10 )
+ ( BlueComponent * 1 ) )
END; (* with *)
RETURN ( colour1 = colour2 );
END CompareCompEqual;
PROCEDURE SortByComponents ( VAR ppalette : PrintPalette; n : CARDINAL );
BEGIN
SortArrayWithKeys( ppalette, ppalette[0], LONG(n), CompareComponents );
END SortByComponents;
(*----------------------------------------------------------------------*)
(* Scan array from Brightest colours to halfway down the array setting *)
(* equal colour entries to the same print pattern from the previous *)
(* entry. Then scan up from the darkest colours to the middle setting *)
(* equal entries to the lower print bit pattern. *)
(* *)
(*----------------------------------------------------------------------*)
PROCEDURE MakeEntriesEqualForLowRes( VAR ppalette : PrintPalette );
VAR i, middle : INTEGER;
finish : BOOLEAN;
BEGIN
SortByComponents( ppalette, 16 );
i := 1;
middle := 8; (* number of last entry affected,
may not get changed if all entries different *)
finish := FALSE; (* scan from darker to lighter first *)
WHILE ( i < 15 )
AND NOT finish DO
IF CompareCompEqual(ppalette[i-1], ppalette[i]) THEN
ppalette[i].PrintBitPattern := ppalette[i-1].PrintBitPattern;
middle := i; (* last entry changed *)
ELSE
IF i > 8 THEN
finish := TRUE;
END;
END;
INC(i);
END;
i := 14;
finish := FALSE; (* scan from darker to lighter *)
WHILE ( i > middle ) DO
IF CompareCompEqual(ppalette[i], ppalette[i+1]) THEN
ppalette[i].PrintBitPattern := ppalette[i+1].PrintBitPattern;
END;
DEC(i);
END;
END MakeEntriesEqualForLowRes;
PROCEDURE MakeEntriesEqualForMedRes( VAR ppalette : PrintPalette );
VAR i, middle : INTEGER;
finish : BOOLEAN;
BEGIN
SortByComponents( ppalette, 4 );
i := 1;
middle := 1; (* number of last entry affected,
may not get changed if all entries different *)
finish := FALSE; (* scan from darker to lighter first *)
WHILE ( i < 3 )
AND NOT finish DO
IF CompareCompEqual(ppalette[i-1], ppalette[i]) THEN
ppalette[i].PrintBitPattern := ppalette[i-1].PrintBitPattern;
middle := i; (* last entry changed *)
ELSE
IF i > 1 THEN
finish := TRUE;
END;
END;
INC(i);
END;
i := 2;
finish := FALSE; (* scan from lighter to darker *)
WHILE ( i > middle ) DO
IF CompareCompEqual(ppalette[i], ppalette[i+1]) THEN
ppalette[i].PrintBitPattern := ppalette[i+1].PrintBitPattern;
END;
DEC(i);
END;
END MakeEntriesEqualForMedRes;
(*----------------------------------------------------------------------*)
(* Convert colours to print bit patterns for current low-res picture *)
(*----------------------------------------------------------------------*)
PROCEDURE SetLowResDefaultPrintPalette ( VAR picturepalette : Palette;
VAR ppalette : PrintPalette );
VAR i : INTEGER;
BEGIN
FOR i := 0 TO 15 DO (* initialise printpalette *)
ppalette[i].ColourIndex := i;
ColourComponents( picturepalette[i],
ppalette[i].RedComponent,
ppalette[i].GreenComponent,
ppalette[i].BlueComponent );
END; (* for *)
DCPicCnv.SortByColour( ppalette, 16 ); (* lightest colours to top *)
ppalette[00].PrintBitPattern := PrintBitPatternSet{ };
ppalette[01].PrintBitPattern := PrintBitPatternSet{ 0 };
ppalette[02].PrintBitPattern := PrintBitPatternSet{ 1 };
ppalette[03].PrintBitPattern := PrintBitPatternSet{ 2 };
ppalette[04].PrintBitPattern := PrintBitPatternSet{ 3 };
ppalette[05].PrintBitPattern := PrintBitPatternSet{ 1, 0 };
ppalette[06].PrintBitPattern := PrintBitPatternSet{ 2, 0 };
ppalette[07].PrintBitPattern := PrintBitPatternSet{ 3, 0 };
ppalette[08].PrintBitPattern := PrintBitPatternSet{ 2, 1 };
ppalette[09].PrintBitPattern := PrintBitPatternSet{ 3, 1 };
ppalette[10].PrintBitPattern := PrintBitPatternSet{ 3, 2 };
ppalette[11].PrintBitPattern := PrintBitPatternSet{ 2, 1, 0 };
ppalette[12].PrintBitPattern := PrintBitPatternSet{ 3, 2, 0 };
ppalette[13].PrintBitPattern := PrintBitPatternSet{ 3, 1, 0 };
ppalette[14].PrintBitPattern := PrintBitPatternSet{ 3, 2, 1 };
ppalette[15].PrintBitPattern := PrintBitPatternSet{ 3, 2, 1, 0 };
MakeEntriesEqualForLowRes( ppalette );
DCPicCnv.SortByIndex( ppalette, 16 );
END SetLowResDefaultPrintPalette;
(*----------------------------------------------------------------------*)
(* Convert colours to print bit patterns for a medium res picture *)
(*----------------------------------------------------------------------*)
PROCEDURE SetMedResDefaultPrintPalette ( VAR picturepalette : Palette;
VAR ppalette : PrintPalette );
VAR i : INTEGER;
BEGIN
FOR i := 0 TO 15 DO (* initialise printpalette *)
ppalette[i].ColourIndex := i;
ColourComponents( 0, (* set all to black to sort to bottom *)
ppalette[i].RedComponent,
ppalette[i].GreenComponent,
ppalette[i].BlueComponent );
END; (* for *)
FOR i := 0 TO 3 DO (* initialise printpalette *)
ColourComponents( picturepalette[i],
ppalette[i].RedComponent,
ppalette[i].GreenComponent,
ppalette[i].BlueComponent );
END; (* for *)
DCPicCnv.SortByColour( ppalette, 4 ); (* lightest colours to top *)
ppalette[00].PrintBitPattern := PrintBitPatternSet{ };
ppalette[01].PrintBitPattern := PrintBitPatternSet{ 1 };
ppalette[02].PrintBitPattern := PrintBitPatternSet{ 0 };
ppalette[03].PrintBitPattern := PrintBitPatternSet{ 1, 0 };
MakeEntriesEqualForMedRes( ppalette );
DCPicCnv.SortByIndex( ppalette, 16 );
END SetMedResDefaultPrintPalette;
END DCConvrt.